#ifndef CS537_2_input_H_GUARD
#define CS537_2_input_H_GUARD

#include <pthread.h>
#include <semaphore.h>

#define MAX_QSIZE 10
#define DEBUG 0

/* 
 * This module is a thread safe (via mutex) blocking 
 * multi-reader/multi-writer queue (semaphores)
 *
 */


/*
 * Element in the array
 */
typedef struct element_t
{
   int size;
   char* string;
   int eof; 
} Element;

/* 
 * Structure used for the queue implementation
 */
typedef struct queue_t
{
   /* queue's array */
   Element* queue_array[MAX_QSIZE];

   /* queue's mutex */
   pthread_mutex_t mutex;

   /* queue's block/delay */
   sem_t read_delay;
   sem_t write_delay;

   /* queue's begin */
   int head;

   /* number of elements queued */
   int count;

} Queue;


/* initializes queue */
Queue* initQueue();

/* add to tail of queue 
 *
 * return 0 for success
 *
 * */
int enqueue(Queue* queue, Element* element);

/* return head element
 *
 * return NULL if empty
 *
 * */
Element* dequeue(Queue* queue);

#endif
